package cn.jbolt.core.util;

import com.jfinal.kit.StrKit;

public class CodeGenKvDataGenUtil {

    public static String gen(String kvDataStr){
        if(StrKit.isBlank(kvDataStr)){return "null";}
        if(!kvDataStr.contains(":")){
            {return "null";}
        }

        String[] arr = JBoltArrayUtil.from3(kvDataStr);
        if(arr==null || arr.length==0){
            return "null";
        }
        String[] temp;
        StringBuilder sb = new StringBuilder();
        for(String a:arr){
            if(!a.contains(":")){continue;}
            temp = JBoltArrayUtil.from(a,":");
            if(temp == null || temp.length == 0){
                continue;
            }
            sb.append(".set(").append("\"").append(temp[0]).append("\",\"").append(temp[1]).append("\"").append(")");
        }
        if(sb.length()==0){
            return "null";
        }
        sb.insert(0,"Kv.create()");
        return sb.toString();
    }
}
